package com.alibaba.algo.core.config;

import com.alibaba.algo.core.base.SslClientHttpRequestFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * Created by IntelliJ IDEA.
 * User: glorysongglory
 * Date: 2020/11/13
 * Time: 14:07
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        return new RestTemplate(factory);
    }

    @Value("${httpcomponent.readTimeout:10000}")
    private Integer readTimeout;

    @Value("${httpcomponent.connectTimeout:60000}")
    private Integer connectTimeout;

    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
        SslClientHttpRequestFactory factory = new SslClientHttpRequestFactory();
        factory.setReadTimeout(readTimeout);
        factory.setConnectTimeout(connectTimeout);
        return factory;
    }
}
